<template>
    <div class="list-content">
        <el-table :data="artical" border class="list-table">
            <el-table-column prop="id" label="id"   class="list-id">
            </el-table-column>
            <el-table-column prop="title" label="标题" class="list-title">
            </el-table-column>
            <el-table-column prop="content" label="内容" >
            </el-table-column>
            <el-table-column  label="操作" >
                <template slot-scope="scope">
                    <el-button  type="text"  size="small" @click="editArtical(scope.row.id)">修改</el-button>
                    <el-button type="text" size="small" @click="removeArtical(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: "ListArtical",
        data() {
            return {
                artical:[],

            }
        },
        methods:{
            //查询
            queryArtical(){
                axios.get('http://localhost:3000/api/getlist',).then((res)=>{
                    this.artical=res.data.message;
                })
            },
            //修改
            editArtical(id){
                this.$router.push(`/edit/${id}`);
            },
            //删除
            removeArtical(id){
               axios.delete(`http://localhost:3000/api/remove/${id}`,id).then(res=>{
                   this.$message({
                       message: '删除文章成功',
                       type: 'success'
                   });
                   this.queryArtical();
               });
            }
        },
        mounted(){
            this.queryArtical();
        }
    }
</script>

<style scoped>
.list-content{
    width: 100%;
}
</style>